package com.ruoyi.web.controller.system;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISystemInitService;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统初始化 控制器
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/init")
public class SysInitController extends BaseController
{
    @Autowired
    private ISystemInitService systemInitService;
    @Autowired
    private ISysConfigService configService;

    /**
     * 清空所有业务表数据
     */
    @PreAuthorize("@ss.hasPermi('system:init:clean')")
    @Log(title = "系统初始化", businessType = BusinessType.CLEAN)
    @PostMapping("/clean")
    public AjaxResult cleanAllData()
    {
        return toAjax(systemInitService.cleanAllData());
    }


    /**
     * 系统计算日期
     */
    @GetMapping("/findRiQi")
    public AjaxResult findRiQi()
    {

        String nian = configService.selectConfigByKey("sys.sjlk.nian");
        String yue = configService.selectConfigByKey("sys.sjlk.yue");
        String ri = configService.selectConfigByKey("sys.sjlk.ri");
        Map<String, Object> result = new HashMap<>();

        result.put("nian",nian);
        result.put("yue",yue);
        result.put("ri",ri);

        return success(result);
    }
} 